from .raw_func import *

class BaseSession():
    def __init__(self, info):
        self.info = info
        self.robot_wxid = self.info.get('robot_wxid', '')
        self.from_wxid = self.info.get('from_wxid', '')

    def send_text_msg(self, msg):
        send_text_msg(self.robot_wxid, self.from_wxid, msg)

    def send_bin_msg(self, msg):
        send_bin_msg(self.robot_wxid, self.from_wxid, msg)

    def send_group_at_msg(self, msg):
        print(self.info['event'])
        if self.info['event'] == 'group_msg':
            send_group_at_msg(self.robot_wxid, self.from_wxid, self.info['final_from_wxid'], self.info['final_from_name'], msg)
        elif self.info['event'] == 'friend_msg':
            self.send_text_msg(msg)

    def send_image_msg(self, path):
        send_image_msg(self.robot_wxid, self.from_wxid, path)

    def send_video_msg(self, path):
        send_video_msg(self.robot_wxid, self.from_wxid, path)

    def send_file_msg(self, path):
        send_file_msg(self.robot_wxid, self.from_wxid, path)

    def send_emoji_msg(self, path):
        send_emoji_msg(self.robot_wxid, self.from_wxid, path)

    def send_link_msg(self, title, text, target_url, pic_url, icon_url):
        send_link_msg(self.robot_wxid, self.from_wxid, title, text, target_url, pic_url, icon_url)

    def send_music_msg(self, name, music_type):
        send_music_msg(self.robot_wxid, self.from_wxid, name, music_type)

    def send_card_info(self, friend_wxid):
        send_card_info(self.robot_wxid, self.from_wxid, friend_wxid)

    def send_mini_app_info(self, xml_content):
        send_mini_app_info(self.robot_wxid, self.from_wxid, xml_content)

    def modify_friend_note(self, note):
        modify_friend_note(self.robot_wxid, self.from_wxid, note)

    def remove_group_member(self, member_wxid):
        remove_group_member(self.robot_wxid, self.from_wxid, member_wxid)

    def modify_group_name(self, group_name):
        modify_group_name(self.robot_wxid, self.from_wxid, group_name)

    def delete_friend(self, friend_wxid):
        delete_friend(self.robot_wxid, friend_wxid)

    def modify_group_notice(self, content):
        modify_group_notice(self.robot_wxid, self.from_wxid, content)

    def building_group(self, friends):
        building_group(self.robot_wxid, friends)

    def quit_group(self, group_wxid):
        quit_group(self.robot_wxid, group_wxid)

    def invite_in_group(self, friend_wxid):
        invite_in_group(self.robot_wxid, self.from_wxid, friend_wxid)

    def set_top_contact(self):
        set_top_contact(self.robot_wxid, self.from_wxid)

    def cancel_top_contact(self):
        cancel_top_contact(self.robot_wxid, self.from_wxid)

    @staticmethod
    def add_log(msg_1, msg_2):
        add_log(msg_1, msg_2)

    def relay_msg(self, to_wxid, msg_id):
        relay_msg(self.robot_wxid, to_wxid, msg_id)

    def get_robot_name(self):
        return get_robot_name(self.robot_wxid)

    def get_robot_headimgurl(self):
        return get_robot_headimgurl(self.robot_wxid)

    @staticmethod
    def get_logged_account_list():
        return get_logged_account_list()

    def get_friend_list(self, is_refresh=0):
        return get_friend_list(self.robot_wxid, is_refresh=is_refresh)

    def get_group_list(self, is_refresh=0):
        return get_group_list(self.robot_wxid, is_refresh=is_refresh)

    def get_group_member_detail(self, member_wxid, is_refresh=0):
        return get_group_member_detail(self.robot_wxid, self.from_wxid, member_wxid, is_refresh=is_refresh)

    def get_group_member_list(self, is_refresh=0):
        return get_group_member_list(self.robot_wxid, self.from_wxid, is_refresh=is_refresh)

    def get_contact_headimgurl(self):
        return get_contact_headimgurl(self.robot_wxid, self.from_wxid)

    def get_friend_list_ext(self, is_refresh=0, out_rawdata=1):
        return get_friend_list_ext(self.robot_wxid, is_refresh=is_refresh, out_rawdata=out_rawdata)

    def get_group_member_list_ext(self, is_refresh=0):
        return get_group_member_list_ext(self.robot_wxid, self.from_wxid, is_refresh=is_refresh)

    def get_group_member_detail_ext(self, member_wxid, is_refresh=0):
        return get_group_member_detail_ext(self.robot_wxid, self.from_wxid, member_wxid, is_refresh=is_refresh)

    def get_group_list_ext(self, is_refresh=0):
        return get_group_list_ext(self.robot_wxid, is_refresh=is_refresh)


class CommandSession(BaseSession):
    def __init__(self, info):
        super().__init__(info)

class RequestSession(BaseSession):
    def __init__(self, info, json_msg):
        super().__init__(info)
        self.json_msg = json_msg

    def agree_friend_verify(self):
        agree_friend_verify(self.robot_wxid, self.json_msg)

    def agree_group_invite(self):
        agree_group_invite(self.robot_wxid, self.json_msg)


class NoticeSession(BaseSession):
    def __init__(self, info, json_msg):
        super().__init__(info)
        self.json_msg = json_msg

    def accept_transfer(self):
        accept_transfer(self.robot_wxid, self.from_wxid, self.json_msg)


class SysSession(BaseSession):
    def __init__(self, info, json_msg):
        super().__init__(info)
